home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Data Manipulation / Remove Points < prev    next >
Text File  |  1996-01-29  |  2KB  |  100 lines

  1. | Version 1.01, 5/17/94
  2. |    Used Wave/D instead of Wave in several places.
  3. | Version 1.10, 12/31/95
  4. |    Updated for Igor Pro 3.0. Removed /D which is no longer needed.
  5.  
  6. #pragma rtGlobals=1
  7.  
  8. | RemoveOutliers(theWave, minVal, maxVal)
  9. |    Removes all points in the wave below minVal or above maxVal.
  10. |    Returns the number of points removed.
  11. Function RemoveOutliers(theWave, minVal, maxVal)
  12.     Wave theWave
  13.     Variable minVal, maxVal
  14.  
  15.     Variable p, numPoints, numOutliers
  16.     Variable val
  17.     
  18.     numOutliers = 0
  19.     p = 0                                            | the loop index
  20.     numPoints = numpnts(theWave)                | number of times to loop
  21.  
  22.     do
  23.         val = theWave[p]
  24.         if ((val < minVal) %| (val > maxVal))    | is this an outlier?
  25.             numOutliers += 1
  26.         else                                        | if not an outlier
  27.             theWave[p - numOutliers] = val        | copy to input wave
  28.         endif
  29.         p += 1
  30.     while (p < numPoints)
  31.     
  32.     | Truncate the wave
  33.     DeletePoints numPoints-numOutliers, numOutliers, theWave
  34.     
  35.     return(numOutliers)
  36. End
  37.  
  38. | RemoveNaNs(theWave)
  39. |    Removes all points in the wave with the value NaN.
  40. |    A NaN represents a blank or missing value.
  41. |    Returns the number of points removed.
  42. Function RemoveNaNs(theWave)
  43.     Wave theWave
  44.  
  45.     Variable p, numPoints, numNaNs
  46.     Variable val
  47.     
  48.     numNaNs = 0
  49.     p = 0                                            | the loop index
  50.     numPoints = numpnts(theWave)                | number of times to loop
  51.  
  52.     do
  53.         val = theWave[p]
  54.         if (numtype(val)==2)                    | is this NaN?
  55.             numNaNs += 1
  56.         else                                        | if not NaN
  57.             theWave[p - numNaNs] = val            | copy to input wave
  58.         endif
  59.         p += 1
  60.     while (p < numPoints)
  61.     
  62.     | Truncate the wave
  63.     DeletePoints numPoints-numNaNs, numNaNs, theWave
  64.     
  65.     return(numNaNs)
  66. End
  67.  
  68. | RemoveNaNsXY(theXWave, theYWave)
  69. |    Removes all points in an XY pair if either wave has the value NaN.
  70. |    A NaN represents a blank or missing value.
  71. |    Returns the number of points removed.
  72. Function RemoveNaNsXY(theXWave, theYWave)
  73.     Wave theXWave
  74.     Wave theYWave
  75.  
  76.     Variable p, numPoints, numNaNs
  77.     Variable xval, yval
  78.     
  79.     numNaNs = 0
  80.     p = 0                                            | the loop index
  81.     numPoints = numpnts(theXWave)            | number of times to loop
  82.  
  83.     do
  84.         xval = theXWave[p]
  85.         yval = theYWave[p]
  86.         if ((numtype(xval)==2) %| (numtype(yval)==2))        | either is NaN?
  87.             numNaNs += 1
  88.         else                                        | if not an outlier
  89.             theXWave[p - numNaNs] = xval        | copy to input wave
  90.             theYWave[p - numNaNs] = yval        | copy to input wave
  91.         endif
  92.         p += 1
  93.     while (p < numPoints)
  94.     
  95.     | Truncate the wave
  96.     DeletePoints numPoints-numNaNs, numNaNs, theXWave, theYWave
  97.     
  98.     return(numNaNs)
  99. End
  100.